package com.yuwei.yurpc.server;

import io.vertx.core.Vertx;

/**
 * 用户服务
 *
 * @author yuwei
 * @date 12:48 2024/10/3
 */
public class VertxHttpServer implements HttpServer{

        @Override
        public void doStart(int port) {
            //创建Vertx实例
            Vertx vertx = Vertx.vertx();
            //创建HttpServer实例
            io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();
            //监听端口
//            httpServer.requestHandler(request -> {
//                System.out.println("收到请求 " + request.uri());
//                request.response()
//                        .putHeader("content-type", "text/plain")
//                        .end("hello world");
//            });
            httpServer.requestHandler(new HttpServerHandler());
            //启动服务
            httpServer.listen(port, res -> {
                if (res.succeeded()) {
                    System.out.println("服务启动成功");
                } else {
                    System.out.println("服务启动失败");
                }

            });
        }
}